package leetcode.list;

import java.util.ArrayDeque;

public class Lc2130 {

    public int pairSum(ListNode head) {
        ArrayDeque<Integer> deque = new ArrayDeque<>();
        int ans = Integer.MIN_VALUE;
        while (head != null) {
            deque.offerLast(head.val);
            head = head.next;
        }
        while (!deque.isEmpty()) {
            ans = Math.max(ans, deque.pollFirst() + deque.pollLast());
        }
        return ans;
    }
}
